package com.yang.singleton;

import java.util.Objects;

/**
 * 懒汉式  线程不安全
 * */
public class Singleton3 {

    //构造方法私有化
    private Singleton3(){}

    private static Singleton3 INSTANCE;

    public static Singleton3 getInstance() {
        if (Objects.isNull(INSTANCE)) {
            try {
                Thread.sleep(10);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            INSTANCE = new Singleton3();
        }
        return INSTANCE;
    }
    public static void main(String[] args) {
        for (int i = 0; i < 50; i++) {
            new Thread(() -> {
                System.out.println(Singleton3.getInstance().hashCode());
            }).start();
        }
    }
}
